import java.util.StringTokenizer;
import java.util.Vector;


class P450_39643 {

	public static void main(String[] args) {
		
		Vector people = new Vector();
		
		int deps = Integer.parseInt(readLn());
		
		String departament = readLn();
		
		
			while (departament != null && !"".equals(departament)) {
			
			String line = readLn();
			
			while (line != null && !"".equals(line)) {
//				System.out.println(">> " + line);
				people.addElement(readPerson(departament, line));
				line = readLn();
			}
			
			departament = readLn();
			
			while (departament != null && "".equals(departament)) {
				departament = readLn();
			}
			
		}
		
		sort(people);
		
		for (int k = 0; k < people.size(); k++) {
			System.out.println(people.elementAt(k));
		}
		
	}
	
	static void sort(Vector lista) {
		for (int i = 1; i < lista.size(); i++) {
			for (int j = lista.size() - 1; j >= i; j--) {
				Person450 p1 = (Person450) lista.elementAt(j - 1);
				Person450 p2 = (Person450) lista.elementAt(j);
				
				if (p1.lastName.compareTo(p2.lastName) > 0) {
					lista.setElementAt(p2, j - 1);
					lista.setElementAt(p1, j);
				}
			}
		}
	}
	
	private static Object readPerson(String department, String line) {
		Person450 p = new Person450();
//		Title, First Name, Last Name, Street Address, 
//		Home Phone, Work Phone, and Campus Mailbox.
		StringTokenizer st = new StringTokenizer(line, ",");
		
		p.department = department;
		p.title = st.nextToken();
		p.firstName = st.nextToken();
		p.lastName = st.nextToken();
		p.address = st.nextToken();
		p.homePhone = st.nextToken();
		p.workPhone = st.nextToken();
		p.campusMail = st.nextToken();
		return p;
	}

	static String readLn() {
		String newLine = System.getProperty("line.separator");
		StringBuffer buffer = new StringBuffer();
		int car = -1;
		try {
			car = System.in.read();
			while ((car > 0) && (car != newLine.charAt(0))) {
				buffer.append((char) car);
				car = System.in.read();
			}
			if (car == newLine.charAt(0))
				System.in.skip(newLine.length() - 1);
		} catch (java.io.IOException e) {
			return (null);
		}
		if ((car < 0) && (buffer.length() == 0))
			return (null);
		return (buffer.toString());
	}

	
}

class Person450 {
//	Title, First Name, Last Name, Street Address, 
//	Home Phone, Work Phone, and Campus Mailbox.
	
	String department;
	String title;
	String firstName;
	String lastName;
	String address;
	String homePhone;
	String workPhone;
	String campusMail;
	
//	--------------------
//
//	<Title> <FirstName> <LastName>
//
//	<HomeAddress>
//
//	Department: <Department>
//
//	Home Phone: <HomePhone>
//
//	Work Phone: <WorkPhone>
//
//	Campus Box: <CampusBox> 
	
	public String toString() {
		StringBuffer sb = new StringBuffer("----------------------------------------\n");
		sb.append(title + " " + firstName + " " + lastName + "\n");
		sb.append(address + "\n");
		sb.append("Department: " + department + "\n");
		sb.append("Home Phone: " + homePhone + "\n");
		sb.append("Work Phone: " + workPhone+ "\n");
		sb.append("Campus Box: " + campusMail);
		return sb.toString();
	}
}